home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / heaptut / examples / basic / heap3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-04  |  677 b   |  31 lines

  1. /* demonstrates static pointer overflow in bss (uninitialized data) */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #include <string.h>
  7. #include <errno.h>
  8.  
  9. #define BUFSIZE 16
  10. #define ADDRLEN 4 /* # of bytes in an address */
  11.  
  12. int main(int argc, char **argv)
  13. {
  14.    u_long diff;
  15.    static char buf[BUFSIZE], *bufptr;
  16.  
  17.    bufptr = buf;
  18.    diff = (u_long)&bufptr - (u_long)buf;
  19.  
  20.    printf("bufptr (%p) = %p, buf = %p, diff = 0x%x (%d) bytes\n",
  21.            &bufptr, bufptr, buf, diff, diff);
  22.  
  23.  
  24.    memset(buf, 'A', (u_int)(diff + ADDRLEN));
  25.  
  26.    printf("bufptr (%p) = %p, buf = %p, diff = 0x%x (%d) bytes\n",
  27.            &bufptr, bufptr, buf, diff, diff);
  28.  
  29.    return 0;
  30. }
  31.